<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>玉米糖</title>
		<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="css/mui.min.css">
		<style type="text/css">
			body,.mui-content{
			  	background-color: #333;
			  	color:#fff;
			  }
			  .title{
			  	margin: 35px 15px 10px;
			  }
			  .title+.content{
			  	margin: 10px 15px 35px;
			  	color: #bbb;
			  	text-indent: 1em;
			  	font-size: 14px;
			  	line-height: 24px;
			  }
			  .mui-table-view{
			  	margin-bottom: 35px;
			  }
		</style>
	</head>

	<body>
		<div class="mui-content" id="slide-menu">
			<!-- <div class="title">导航栏</div>			
			<div class="title" style="margin-bottom: 25px;">菜单</div> -->
			<ul id="urld" class="mui-table-view mui-table-view-chevron mui-table-view-inverted" style="color: #ddd;">
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right" open-type="common" href="#">
						<img src="images/loading.gif" alt="正在加载...">加载中...
					</a>
				</li>
				
			</ul>
		</div>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript" charset="utf-8">
			var aniShow = "slide-in-right";
			var subWebview=null,template=null,index=null;
			mui.plusReady(function () {
				//获得主页面webview引用；
				index = plus.webview.currentWebview().opener();
				plus.storage.removeItem("slideMenu");
				//读取本地存储
				var slideMenu = plus.storage.getItem("slideMenu");
				if(slideMenu){
					getSlideMenu();
					mui('#slide-menu').innerHTML(slideMenu.data);
					var datetime=getDateTime();
					if(datetime+86400>slideMenu.datetime){
						getSlideMenu();
					}
				}else{
					getSlideMenu();
				}			
			});
			getSlideMenu();
			var slidemenu=document.getElementById("slide-menu");
			var dt=slidemenu.querySelector(".mui-table-view ");
			function getSlideMenu(){
				console.log(123);
			
					mui.post('http://www.5iymt.com/index.php?g=App&m=Index&a=get_menu',{
						username:'123',
						password:'password'
					},function(data){
						//服务器返回响应，根据响应结果，分析是否登录成功；
						console.log(data);
						console.log(data.status);
						//服务器返回响应，根据响应结果，分析是否登录成功；
						//alert(data.status);
						if(data.status){
							var html='';							
							var slidedata=data.data;
							/*mui.each(slidedata,function(){
								html+="<li class='mui-collapse mui-table-view-cell' id= 'menu-item-1'>"+
								"<a class='mui-navigate-right' href='examples/media-list.html' open-type='common'>"+this.label+" </a>'</li>";
							});*/
							html+=slidedata;
							console.log(html);
							slidemenu.innerHTML=html;
							var datatime=getDateTime();	
							var slideMenu={'data':html,'datatime':datatime}
							//保存缓存
							plus.storage.setItem("slideMenu", slideMenu);
						}else{
							alert('error');
						}
					},'json'
				);
			}

			function getDateTime(){
				var date=new Date();
				return date.getTime();
			}

			mui('.mui-table-view').on('tap', 'a', function() {
				var id = this.getAttribute("href");
				var type = this.getAttribute("open-type");
				var href = this.href;
				if(type=="common"||mui.os.ios){
					var webview_style = {
						popGesture: "close"
					};
					mui.openWindow({
						id: id,
						url: href,
						styles: webview_style,
						show: {
							aniShow: aniShow
						},
						waiting: {
							autoShow: false
						}
					});
				}else{
					var href = this.href;
					var title = this.innerText;
					template = plus.webview.getWebviewById("default-main");
					//获得共用子webview
					subWebview = template.children()[0];
					
					//通知模板修改标题，并显示隐藏右上角图标；
					mui.fire(template,'updateHeader',{title:title,showMenu:false});
					if (subWebview.getURL() != href) {
						subWebview.loadURL(href);
					} else {
						 subWebview.show();
					}
					template.show('slide-in-right', 150);
				}
			});
			
			/**
			 * 关闭侧滑菜单
			 */
			function close() {
				mui.fire(mui.currentWebview.opener(),"menu:close");
			}
			
			//点击“关闭侧滑菜单”按钮处理逻辑
			//document.getElementById("close-btn").addEventListener("tap",close);
			//在android4.4.2中的swipe事件，需要preventDefault一下，否则触发不正常
			window.addEventListener('dragstart',function(e){
				mui.gestures.touch.lockDirection = true; //锁定方向
				mui.gestures.touch.startDirection = e.detail.direction;
			});
			window.addEventListener('dragleft', function(e) {
				if(!mui.isScrolling){
					e.detail.gesture.preventDefault();	
				}
			});
			//监听左滑事件，若菜单已展开，左滑要关闭菜单；
			window.addEventListener("swipeleft",function (e) {
				if(Math.abs(e.detail.angle)>170){
					close();						
				}
			});
			//监听正在加载触发
			//document.getElementById('slide-onload').addEventListener("tap",getSlideMenu);
		</script>
	</body>

</html>